package com.wisdom;


import java.io.File;
import java.util.List;

import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.media.AudioManager;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.view.KeyEvent;
import android.widget.Toast;

import com.wisdom.bean.ContactBean;
import com.wisdom.service.T9Service;
import com.wisdom.tools.CCPConfig;
import com.wisdom.voip.VoiceHelper;

public class VoiceApplication extends Application {
    private static VoiceApplication instance;
    
    private VoiceHelper voiceHelper;
    private File vStore;
    public final static String VALUE_DIAL_MODE_FREE = "voip_talk";
	public final static String VALUE_DIAL_MODE_BACK = "back_talk";
	public final static String VALUE_DIAL_MODE_DIRECT = "direct_talk";
	public final static String VALUE_DIAL_MODE = "mode";
	public final static String VALUE_DIAL_SOURCE_PHONE= "srcPhone";
	public final static String VALUE_DIAL_VOIP_INPUT = "VoIPInput";
	public final static String VALUE_DIAL_MODE_VEDIO = "vedio_talk";
       
    @Override
    public void onCreate(){
    	super.onCreate();
    	instance=this;
    	CCPConfig.initProperties(getApplicationContext());
    	initFileStore();
    	
    	System.out.println("项目启动");
    	
//    	Intent startService=new Intent(VoiceApplication.this,T9Service.class);
//    	startService(startService);
    	
    }
	private void initFileStore() {
		File directory = new File(Environment.getExternalStorageDirectory(),"voiceDemo");
		if (!directory.exists() && !directory.mkdirs()) { 
			Toast.makeText(getApplicationContext(), "Path to file could not be created", Toast.LENGTH_SHORT).show();
			return;
		} 
		vStore = directory;
	}
	public File getVoiceStore(){
		return vStore;
	}

    /**
	 * 设置播放模式
	 * @param mode
	 */
	public void setAudioMode(int mode) {
		AudioManager audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
		if (audioManager != null) {
			audioManager.setMode(mode);
		}
	}
   	public static VoiceApplication getInstance() {
		return instance;
	}
   	
   	/**
	 * @return the voiceHelper
	 */
	public VoiceHelper getVoiceHelper() {
		return voiceHelper;
	}
private boolean isConnect = false;
	
	public boolean isConnect() {
		return isConnect;
	}
	public void setConnect(boolean isConnect) {
		this.isConnect = isConnect;
	}

	public void initVoiceHelper(Handler handler){
		voiceHelper=new VoiceHelper(getApplicationContext(),handler);
	}
	
   	public void showToast(String text) {
		Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
	}
   	public void showToast(int resId){
   		Toast.makeText(getApplicationContext(), resId,Toast.LENGTH_SHORT);
   	}
   	/**
	 * device factory name, e.g: Samsung
	 * 
	 * @return the vENDOR
	 */
	public String getVendor() {
		return Build.BRAND;
	}
   	/**
	 * Retrieves application's version number from the manifest
	 * 
	 * @return versionName
	 */
	public String getVersion() {
		String version = "0.0.0";
		try {
			PackageInfo packageInfo = getPackageManager().getPackageInfo(
					getPackageName(), 0);
			version = packageInfo.versionName;
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}

		return version;
	}
	/**
	 * device model name, e.g: GT-I9100
	 * 
	 * @return the user_Agent
	 */
	public String getDevice() {
		return Build.MODEL;
	}
   	public String getOSVersion() {
		return Build.VERSION.RELEASE;
	}
   	/**
	 * User-Agent
	 * 
	 * @return user-agent
	 */
	public String getUser_Agent() {
		String ua = "Android;" + getOSVersion() + ";" + getVersion() + ";"
				+ getVendor() + "-" + getDevice();
		return ua;
	}
	
	
	private List<ContactBean> contactBeanList;
	public List<ContactBean> getContactBeanList(){
		return contactBeanList;
	}
	public void setContactBeanList(List<ContactBean>contactBeanList){
		this.contactBeanList=contactBeanList;
	}
	
	
}
